const { Service } = require('egg');

class UserService extends Service {
    async readByUsername(username) {
        let res = await this.app.mysql.query(
            'select * from user where username = ? limit 0, 1',
            [username],
        );
        return res[0];
    }

    async create({ username, password, nickname }) {
        return await this.app.mysql.query(
            'insert into user (username, password, nickname) values (?, ?, ?)',
            [username, password, nickname],
        );
    }
}

module.exports = UserService;
